import requests
from util.logger import get_looger
import time

# 动态页面刷新
# logger = get_looger('bilibili', __file__)
# logger.info('开始爬取数据')
# page = 1
# while True:
#     url = f'https://api.bilibili.com/pgc/season/index/result?st=1&year=%5B2025%2C2026)&season_version=-1&spoken_language_type=-1&area=-1&is_finish=-1&copyright=-1&season_status=-1&season_month=-1&style_id=-1&order=3&sort=0&page={page}&season_type=1&pagesize=20&type=1'
#     logger.info(f'正在爬取第{page}页')
#     response = requests.get(url, headers={
#         'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
#     })
#     try:
#         datas = response.json()
#         data = datas['data']
#         items = data['list']
#         if response.status_code == 200:
#             for item in items:
#                 title = item['title']
#                 print(title)
#
#         else:
#             logger.error(response.status_code)
#         if data['has_next']:
#             page += 1
#             print(page)
#         else:
#             break
#     except Exception as e:
#         logger.error(e)
# logger.info('所有页面爬取完毕')

# 动态局部刷新
# time_stemp = int(time.time()*1000)
# url = (f'https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd?web_location=1430650'
       # '&ps=10'
#        f'&wts={time_stemp}')
# response = requests.get(url, headers={
#        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
#        'referer':'https://www.bilibili.com/'
# })
# items = response.json()['data']['item']
# for item in items:
#        print(item['title'])


# 服务器本地获取数据无刷新



